﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using imaginecup.information;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.util;
using Imaginecup.gameState.malaria.manager;
using Microsoft.Xna.Framework.Input;
using Imaginecup.gameState.malaria.component.util;
using Microsoft.Xna.Framework;
using Imaginecup.util.collision;
using Imaginecup.util.particle;
using imaginecup.util;
using Imaginecup.util.script.malaria;
using Imaginecup.gameState.malaria.component.entity.effect;

namespace Imaginecup.gameState.malaria.component.entity.item
{
    public class CmpHandAttack : BaseCoolTimeItemEntityComponent
    {
        private List<ICmpMalaria> m_MalariaList;
        private AttackInfo m_AttackInfo;

        private int m_Count;

        public CmpHandAttack(GObjectID a_GID, ObjectManager objMan )
            : base(a_GID, objMan, ComponentTypeID.CID_ITEM_ENTITY)
        {
            m_MalariaList = new List<ICmpMalaria>();
            m_AttackInfo = new AttackInfo();
            m_AttackInfo.attackID = AttackID.ATTACK_HAND;
            m_AttackInfo.extraData = m_MalariaList;

            m_CoolTime = 5;
            m_Count = 5;
        //    m_UseAbleTime = 5;
//#if WINDOWS
//            m_CoolTime = ScriptReader.GetScriptReader().GetDataToFloat("파리채쿨타임");
//        //    m_UseAbleTime = ScriptReader.GetScriptReader().GetDataToFloat("파리채시간");
//#endif

        }

        public override EMessageResult HandleMessage(GMessage a_Msg)
        {
            
            return base.HandleMessage(a_Msg);
        }

        public override bool IsUseAble()
        {
            if (m_State == CoolState.None)
            {
                m_Count = 5;
            }

            if( base.IsUseAble() == false ) return false;

            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            Vector2 screen = MalariaState.GetMalariaState().GetMainScreenSize();

            if (input.IsOneClick() && Collision.ContainPoint(Vector2.Zero, screen, input.Position))
            {
                GMessage message = new GMessage(MessageTypeID.MT_CHECK_ATTACK);
                //마우스 충돌이 일어난 엔티티들을 등록할 수 있다.
                message.m_Data = m_AttackInfo;

                m_ObjectMan.BroadCastMessage(message, ComponentTypeID.CID_MALARIA_ENTITY);

                if (m_MalariaList.Count > 0)
                {
                    return true;
                }

            }
            return false;
        }

        protected override void SetClear()
        {

        }


        public override void UseItem(GameTime gameTime)
        {            
            m_MalariaList[0].AddDemage(-10);

            FlySwatterEffect flySwatterEffect = new FlySwatterEffect(new GObjectID(), m_ObjectMan, m_MalariaList[0]);
            m_ObjectMan.AddComponent(flySwatterEffect);

            m_MalariaList.Clear();

            m_Count--;

            if( m_Count == 0 )
            {
                SetClear();
                m_CoolCalculateTime = m_CoolTime;
                m_State = CoolState.Delay;
                m_bEnd = true;
                m_bSelectItem = false;
            }

        }

    }
}
